<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="使用日期" prop="syrq">
        <el-date-picker :editable="false" clearable size="small" v-model="queryParams.syrq" type="date"
          value-format="yyyy-MM-dd" placeholder="选择使用日期">
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="检测项目" prop="jcxm">
        <el-input
          v-model="queryParams.jcxm"
          placeholder="请输入检测项目"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['Productionline_conductivity:conductivity:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['Productionline_conductivity:conductivity:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['Productionline_conductivity:conductivity:remove']">删除</el-button>
        <el-button type="warning" plain icon="el-icon-s-check" size="mini" :disabled="multiple" @click="handleCheck"
          v-hasPermi="['Productionline_conductivity:conductivity:check']">审核</el-button>
      </el-col>
      <!--  <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['Productionline_conductivity:conductivity:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="conductivityList" @selection-change="handleSelectionChange" max-height="550">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" width="100px" />
      <el-table-column label="使用日期" align="center" prop="syrq">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.syrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电导率状态是否良好" align="center" prop="jcxm" />
      <el-table-column label="检测是否准确" align="center" prop="jcsfzq" />
      <el-table-column label="是否校正" align="center" prop="sfjz" />
      <el-table-column label="校准后检测是否准确" align="center" prop="jzhjcsfzq" />

      <el-table-column label="审核状态" align="center" prop="auditor" :formatter="laboratory_Microbe_jyxm_Format" />
      <el-table-column label="报表编号" align="center" prop="bbbh" />
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="250px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="excelhandleView(scope.row)">导出</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['Productionline_conductivity:conductivity:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['Productionline_conductivity:conductivity:remove']">删除</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改电导率仪校正记录表对话框 -->
    <el-dialog v-myFullscreen :title="title" :visible.sync="open" width="900" custom-class="myDialog" append-to-body
      fullscreen>
      <TableHeader @nameChange="nameChange" :data="{
          mainTitle: '电导率仪校正记录表',
          company: '青岛崂山矿泉水有限公司',
          code: form.bbbh,
        }" />
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="使用日期" prop="syrq">
              <el-date-picker :editable="false" clearable v-model="form.syrq" type="date" value-format="yyyy-MM-dd"
                placeholder="选择使用日期" :disabled="openDisabled">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="电导率状态是否良好" prop="jcxm">
              <!-- <el-input
                v-model="form.jcxm"
                placeholder="请输入电导率状态是否良好"
                :disabled="openDisabled"
              /> -->
              <el-select label="" v-model="form.jcxm">
                <el-option value="是">是</el-option>
                <el-option value="否">否</el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检测是否准确" prop="jcsfzq">
              <!-- <el-input
                v-model="form.jcsfzq"
                placeholder="请输入检测是否准确"
                :disabled="openDisabled"
              /> -->
              <el-select label="" v-model="form.jcsfzq">
                <el-option value="是">是</el-option>
                <el-option value="否">否</el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>



          <el-col :span="12">
            <el-form-item label="校准后检测是否准确" prop="jzhjcsfzq">
              <!-- <el-input
                v-model="form.jzhjcsfzq"
                placeholder="请输入校准后检测是否准确"
                :disabled="openDisabled"
              /> -->
              <el-select label="" v-model="form.jzhjcsfzq">
                <el-option value="是">是</el-option>
                <el-option value="否">否</el-option>
                <el-option value="/">/</el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否校正" prop="sfjz">
              <!-- <el-input
                v-model="form.sfjz"
                placeholder="请输入是否校正"
                :disabled="openDisabled"
              /> -->
              <el-select label="" v-model="form.sfjz">
                <el-option value="是">是</el-option>
                <el-option value="否">否</el-option>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="操作人" prop="operator">
              <!-- <UserDialog
                @dialogChange="form.operator = $event.label"
                :echoValue="form.operator"
                :multiple="false"
                placeholder="请选择人员"

              /> -->
              <el-input v-model="form.operator" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审核人" prop="auditor">
              <el-input v-model="form.auditor" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input type="textarea" v-model="form.remark" placeholder="请输入备注" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listConductivity,
    getConductivity,
    delConductivity,
    addConductivity,
    updateConductivity,
    checkConductivity,
  } from "@/api/quality/productionline/conductivity";

  export default {
    name: "Conductivity",
    data() {
      return {
        //弹窗是否禁止编辑
        openDisabled: true,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 电导率仪校正记录表表格数据
        conductivityList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 50,
          type:2,
          syrq: null,
          jcxm: null,
          operator: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
      };
    },
    created() {
      this.getList();
    },
    methods: {
      laboratory_Microbe_jyxm_Format(row, column) {
        if (row.auditor == null || row.auditor == "") {
          return "未审核";
        } else {
          return "已审核";
        }
        // return this.selectDictLabel(this.laboratory_Microbe_jyxm, row.jyxm);
      },
      /** 审核按钮操作 */
      handleCheck(row) {
        /* 审核 */
        // console.log(row);
        this.ids.forEach((id) => {
          let flag = true;
          for (let x = 0; x < this.conductivityList.length; x++) {
            if (this.conductivityList[x].id == id) {
              if (this.conductivityList[x].auditor != null) {
                flag = false;
                this.msgError(
                  '编号为"' + id + '"的数据项已审核完成，无需重复审核！'
                );
                break;
              }
            }
          }
          if (flag) {
            let obj = {};
            obj.id = id;
            obj.auditor = this.$store.state.user.nickName;
            checkConductivity(obj).then((response) => {
              this.msgSuccess("审核成功");
              this.getList();
            });
          }
        });

        // this.ids.forEach((id) => {
        // getBulk_record(id).then((response) => {
        //   if (response.data.auditor != null && response.data.auditor != "") {
        //     this.msgError(
        //       '编号为"' + id + '"的数据项已审核完成，无需重复审核！'
        //     );
        //   } else {
        //     let obj = {};
        //     obj.id = id;
        //     obj.auditor = this.nickName;
        //     obj.rptProBulkingList = this.rptProBulkingList;
        //     obj.rptProBulkingSterilizeList = this.rptProBulkingSterilizeList;
        //     obj.rptProBulkingDayList = this.rptProBulkingDayList;
        //     obj.rptProBulkingCheckList = this.rptProBulkingCheckList;
        //     /* 修改 */
        //     updateBulk_record(obj).then((response) => {
        //       this.msgSuccess("审核成功");
        //       this.getList();
        //     });
        //   }
        // });
        // });
      },
      /** 查询电导率仪校正记录表列表 */
      getList() {
        this.loading = true;
        listConductivity(this.queryParams).then((response) => {
          this.conductivityList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          syrq: null,
          jcxm: null,
          jcsfzq: null,
          sfjz: null,
          jzhjcsfzq: null,
          type: 2,
          auditor: null,
          operator: null,
          bbbh: "LK-QF-LS1-10-015-11-05",
          remark: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          delFlag: null,
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map((item) => item.id);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.openDisabled = false;
        this.open = true;
        this.title = "添加电导率仪校正记录表";
        this.form.operator = this.$store.state.user.nickName;
        this.form.jcxm = "是";
        this.form.type =2;
        this.form.jcsfzq = "是";
        this.form.sfjz = "否";
        this.form.jzhjcsfzq = "/";

        // console.log(this.$store.state.user);

        // console.log(this.form.operator );
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.openDisabled = false;
        const id = row.id || this.ids;
        this.queryParams.operator = null;
        getConductivity(id).then((response) => {
          this.form = response.data;
          this.open = true;
          this.title = "修改电导率仪校正记录表";
        });
      },
      /** 查看按钮 */
      handleView(row) {
        this.reset();
        this.openDisabled = true;
        const id = row.id || this.ids;
        getConductivity(id).then((response) => {
          this.form = response.data;
          this.open = true;
          this.title = "查看电导率仪校正记录表";
        });
      },

      excelhandleView(row) {
        this.download(
          "Productionline/conductivity/exportexcel?id=" + row.id,
          {
            ...this.queryParams,
          },
          "新版PH计电导率使用记录" + this.parseTime(new Date()) + ".xlsx"
        );
      },

      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate((valid) => {

          if (valid) {
            /**打开遮罩层*/
            const rLoading = this.openLoading();
            if (this.form.id != null) {
              updateConductivity(this.form)
                .then((response) => {
                  /**成功后执行关闭遮罩层*/
                  rLoading.close();
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                })
                .catch((error) => {
                  /**请求异常后执行关闭遮罩层*/
                  rLoading.close();
                });
            } else {
              addConductivity(this.form)
                .then((response) => {
                  /**成功后执行关闭遮罩层*/
                  rLoading.close();
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                })
                .catch((error) => {
                  /**请求异常后执行关闭遮罩层*/
                  rLoading.close();
                });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm(
          '是否确认删除电导率仪校正记录表编号为"' + ids + '"的数据项?',
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(function () {
            return delConductivity(ids);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("删除成功");
          })
          .catch(() => { });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(
          "Productionline_conductivity/conductivity/export",
          {
            ...this.queryParams,
          },
          `Productionline_conductivity_conductivity.xlsx`
        );
      },
      //接收编号
      nameChange(e) {
        this.form.bbbh = e;
      },
    },
  };
</script>